# Definition for singly-linked list.
class ListNode(object):
    def __init__(self, x):
        self.val = x
        self.next = None
    def __repr__(self):
        return str(self.val)

class Solution(object):
    def removeElements(self, head, val):
        header = ListNode(0)
        tmp = header
        while head:
            if head.val!=val:
                tmp.next = head
                head = head.next
                tmp = tmp.next
                tmp.next = None
            else:
                head = head.next
        return header.next

head = ListNode(1)
print(Solution().removeElements(head, 1))
